package leetcode.code1980;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public String findDifferentBinaryString(String[] nums) {
		int n = nums.length;
		Set<Integer> set = new HashSet<>();
		for (int i = 0; i < nums.length; i++) {
			String str = nums[i];
			int num = 0;
			for (int j = 0; j < n; j++) {
				int cur = str.charAt(j) - '0';
				cur <<= n - 1 - j;
				num |= cur;
			}
			set.add(num);
		}
		int range = (int) Math.pow(2, n);
		int ansNum = 0;
		while (ansNum < range) {
			if (set.contains(ansNum)) {
				ansNum++;
			} else {
				break;
			}
		}
		char[] ans = new char[n];
		Arrays.fill(ans, '0');
		int p = n - 1;
		while (ansNum > 0) {
			int last = ansNum & 1;
			ans[p--] = (char) (last + '0');
			ansNum >>= 1;
		}
		return new String(ans);
	}

	@Override
	public void debug4() {
		H.compare("10", this.findDifferentBinaryString(H.str2array2("[\"00\",\"01\"]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
